package com.interf;

import com.interf.wms.DBUtil;
import java.util.Map;

/**
 * 对接蓝天亮灯、立库中间表
 */
public class WCSUtils {
	/**
	 * 物料上架
	 * @param wCode      仓库编码
	 * @param orderCode  订单号
	 * @param rfid		 多个RFID使用,隔开
	 * @param productCodes  物料编码，多个使用,隔开
	 * @param productNames  物料名称，多个石红中文逗号隔开
	 */
	public static void inStorck(String wCode, String orderCode, String rfid, String productCodes, String productNames, float qty) {
		save(wCode, orderCode, rfid, productCodes, productNames, "10", qty, orderCode);
	}
	/**
	 * 物料下架
	 * @param wCode    仓库编码
	 */
	public static void outStorck(String wCode, String rfidCode, float qty, String orderCode) {
		save(wCode, rfidCode, "", "", "", "20", qty, orderCode);
	}
	/**
	 * 判断中间表数量是否足够
	 * @param wCode    仓库编码
	 * @param orderCode		RFID
	 */
	public static int check(String wCode, String orderCode) {
		String sql = "select sum(INVENTORY_QTY) qty from hddata.v_WMS_INVENTORY_QTY where AREA_CODE = ? and ORDERCODE = ?";
		Map<String, Object> map = DBUtil.queryUnique(sql, wCode, orderCode);
		if (map != null && map.get("QTY") != null) {
			return Integer.parseInt(map.get("QTY").toString());
		}
		return 0;
	}

	private static void save(String wCode, String orderCode, String rfid,
							 String productCodes, String productNames, String type, float qty, String taskCode) {
		try {
			String sql = "insert into hddata.s_wms_in_out_list (STCODE, CREATEUSER, CREATETIME, " +
					"WAREID, WARENAME, RFIDCODE, ORDERCODE, INOUT, QTY, FLAG, docno) " +
					"values (?, ?, now(), ?, ?, ?, ?, ?, ?, 0, ?)";
			DBUtil.execute(sql, wCode, "MES", productCodes, productNames, rfid, orderCode, type, qty, taskCode);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}